import request from '@/utils/request.js'

let systemInfo = uni.getStorageSync('systemInfo')

function connectBody(body = null) {
	// 将输入字符串转换为小写，统一处理
	let lowerStr = uni.getStorageSync('systemInfo').system.toLowerCase();
	let systemString = uni.getStorageSync('systemInfo').system
	let osType = null
	switch (true) {
		case lowerStr.includes('android') || systemString.includes('安卓'):
			osType = 1; // 安卓
			break
		case lowerStr.includes('ios') || systemString.includes('iOS'):
			osType = 2; // iOS
			break
		case lowerStr.includes('harmonyos') || systemString.includes('鸿蒙'):
			osType = 3; // 纯血鸿蒙
			break
		default:
			osType = 4; // 其他
			break
	}
	let data = {
		"head": {
			"appId": "1043",
			"channelFlag": "",
			"imei": "",
			"oaid": "", //clue_token
			"idfa": "", //promotion_id
			"mac": "",
			"model": uni.getStorageSync('systemInfo').model,
			"appVer": uni.getStorageSync('systemInfo').appVersion,
			"osType": osType,
			"osVer": uni.getStorageSync('systemInfo').osVersion,
		},
		"body": body
	}
	return data
}

// 登录
export function login(data) {
	return request.post('/api/auth/v1/wx_login', connectBody(data))
}

// app初始化
export function appInit() {
	return request.post('/api/auth/v1/init', connectBody())
}

// 账单列表
export function getAccountList(data) {
	return request.post('/api/auth/v1/ai_account_list', connectBody(data))
}

// 获取本月支出，收入
export function getAccountByMonth(data) {
	return request.post('/api/auth/v1/ai_account_month_data', connectBody(data))
}
// 修改账单
export function editAccount(id, data) {
	return request.put(`/api/auth/v1/ai_account/${id}`, connectBody(data))
}

// AI记账
export function aiAccount(data) {
	return request.post('/api/auth/v1/ai_account', connectBody(data))
}

// AI记账 删除
export function delAccount(id, uid) {
	return request.delete(`api/auth/v1/ai_account/${id}`, connectBody(uid))
}

// 获取腾讯云语音识别临时密码
export function getAsrKey(data) {
	return request.post('/api/auth/v1/asr_key', connectBody(data))
}
export function getCosKey(data) {
	return request.post('/api/auth/v1/cos_key', connectBody(data))
}

export function getMessageList(data) {
	return request.post('/api/auth/v1/send_extra_data', connectBody(data))
}